<?php /* Smarty version 2.6.20, created on 2016-04-11 19:55:22
         compiled from district.htm */ ?>
<div class="container">
    <ul class="district clearfix">
    <?php $_from = $this->_tpl_vars['pv']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['num'] => $this->_tpl_vars['list']):
?>
        <li>
            <label class="province"><input type="checkbox" name="provs[]"/><?php echo $this->_tpl_vars['list']['name']; ?>
&nbsp;<em></em></label>
            <div class="city_box">
            <?php $_from = $this->_tpl_vars['list']['city']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['cnum'] => $this->_tpl_vars['slist']):
?>
                <label class="city"><input type="checkbox" value="<?php echo $this->_tpl_vars['slist']['id']; ?>
" /><?php echo $this->_tpl_vars['slist']['name']; ?>
</label>
            <?php endforeach; endif; unset($_from); ?>
            <a class="close" href="javascript:void(0);">关闭</a>
            </div>
        </li>
    <?php endforeach; endif; unset($_from); ?>
    </ul>
    <div class="dialog_button">
        <input class="save" type="button" value="确定"> 
    </div>
</div>
<script type="text/javascript">
	
Array.prototype.in_array = function(e)
{
	for(i=0;i<this.length && this[i]!=e;i++);
	return !(i==this.length);
}
if(input.val())
{
	array=input.val().split(",");
	$('.city').find('input[type="checkbox"]').each(function(){
		if(array.in_array($(this).val()))
		{
			$(this).attr('checked','checked');
			li=$(this).parent().parent().parent();
			checkbox=li.children(".city_box").find('input[type="checkbox"]:checked');
			em=li.find('em');
			em.html("("+checkbox.length+")");
			if(checkbox.length==1)
			li.find('input[name="provs[]"]').attr("checked",true);
		}
	});
}
$('input[name="provs[]"]').unbind().click(function(){
							   	
	aa=$(this).parent().parent().parent();
	li=$(this).parent().parent();
	checkbox=li.children(".city_box").find('input[type="checkbox"]');
	em=$(this).parent().find('em');
	aa.find('.city_box').hide();
	li.find(".city_box").show();
	li.addClass("selected").siblings().removeClass("selected");
	if($(this).attr("checked")==true)
	{
		checkbox.attr("checked",true);
		em.html("("+checkbox.length+")");
	}
	else
	{
		checkbox.attr("checked",false);
		em.html("");
	}
});
$(".district .city_box").find('input[type="checkbox"]').unbind().click(function(){
	li=$(this).parent().parent().parent();
	div=$(this).parent().parent();
	checkbox=div.find('input[type="checkbox"]:checked');
	if(checkbox.length>0)
	{
		em=li.find('em');
		em.html("("+checkbox.length+")");
		li.find('input[name="provs[]"]').attr("checked",true);
	}
});
$('.close').unbind().click(function(){
	li=$(this).parent().parent();
	checkbox=li.children(".city_box").find('input[type="checkbox"]:checked');
	em=li.find('em');
	li.find('.city_box').hide();
	li.removeClass("selected");
	em.html("("+checkbox.length+")");
});
$('.save').unbind().click(function(){
	$('.city').find('input[type="checkbox"]:checked').each(function(){
		sca.push($(this).val());
		sct.push($(this).parent('label').text());
	});
	if(sca)
	{
		input.val(','+sca+',');
		span.html(sct.join()+"&nbsp;");
	}
	DialogManager.close("district");
});
</script>